package com.fuyd.pms.background.service;

import com.fuyd.pms.background.repository.MerchandiseDao;
import com.fuyd.pms.entity.Merchandise;
import com.fuyd.pms.utils.Clock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 商品管理的Service
 * Created by fuyongde on 2015/12/25.
 */
@Service
public class MerchandiesService {

    /**默认的时钟构造器**/
    private Clock clock = Clock.DEFAULT;

    /**商品的Dao**/
    private MerchandiseDao merchandiseDao;

    @Autowired
    public MerchandiseDao getMerchandiseDao() {
        return merchandiseDao;
    }

    /**
     * 添加商品
     * @param merchandise
     */
    @Transactional
    public Merchandise add(Merchandise merchandise) {
        merchandise.setCreated(clock.getCurrentDate());
        merchandise.setUpdated(clock.getCurrentDate());
        return merchandiseDao.save(merchandise);
    }
}
